package org.csu.xzypetstore.controller;

import org.csu.xzypetstore.domain.Admin;
import org.csu.xzypetstore.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/admin/")
public class admin {

    @Autowired
    private AdminService adminService;

    @PostMapping("login")
    @ResponseBody
    public String AdminLogin(String username, String password){

        Admin admin = adminService.getAccountByUserAndPwd(username,password);
        if(admin==null)
        {
            return "0";
        }
        else
        {
            return "1";
        }
    }

    @GetMapping("adminMain")
    public String adminLogin()
    {
        return "admin/adminMain";
    }

    @GetMapping("loginView")
    public String adminLoginView()
    {
        return "admin/adminLogin";
    }


}
